// import service, { doGet } from '@/router/axios'

/**
 * @Date 2021/1/5 15:16
 * @Author XQC
 * @Description  组装每个属性
 */
function pageColumnData(col) {
  const pageColumn = {}
  pageColumn.label = col.columnDes
  pageColumn.prop = col.columnName
  pageColumn.fixed = false
  if (col.isList != '1') { // 是否列表显示
    pageColumn.hide = true
  }
  if (col.isEdit != '1' || (col.strongCode != '' && col.strongCode != null && col.strongCode != 'null')) { // 自动赋值的，也隐藏
    pageColumn.editDisplay = false
  } else {
    pageColumn.editDisplay = true
  }
  if (col.isAdd != '1' || (col.strongCode != '' && col.strongCode != null && col.strongCode != 'null')) { // 自动赋值的，也隐藏
    pageColumn.addDisplay = false
  } else {
    pageColumn.addDisplay = true
  }
  if (col.isSelect === '1') {
    pageColumn.search = true
  }

  // 输入框选择
  if (col.columnInputType == '01') {
    pageColumn.type = 'textarea'
  } else if (col.columnInputType == '02') {
    pageColumn.type = 'select'
    pageColumn.dicData = []
  } else if (col.columnInputType == '03') {
    pageColumn.type = 'tree'
    pageColumn.dicData = []
  } else if (col.columnInputType == '04') {
    pageColumn.type = 'date'
    pageColumn.format = 'yyyy-MM-dd'
    pageColumn.valueFormat = 'yyyy-MM-dd'
  } else if (col.columnInputType == '05') {
    pageColumn.type = 'datetime'
    pageColumn.format = 'yyyy-MM-dd hh:mm:ss'
    pageColumn.valueFormat = 'yyyy-MM-dd hh:mm:ss'
  } else if (col.columnInputType == '06') {
    pageColumn.type = 'password'
  }
  if (col.columnType === 'DATE') {
    pageColumn.format = 'yyyy-MM-dd'
  } else if (col.columnType === 'DATETIME') {
    pageColumn.format = 'yyyy-MM-dd hh:mm:ss'
  }
  // 规则校验
  const ruleParams = []
  const requiredPara = { trigger: 'blur', message: '请输入' + col.columnDes }
  if (col.isRequired == '1' && (col.strongCode == '' || col.strongCode == null || col.strongCode == 'null')) {
    requiredPara.required = true
  } else {
    requiredPara.required = false
  }
  if (col.columnValidateType == '01') { // 验证邮箱
    requiredPara.type = 'email'
  }
  if (col.columnValidateType == '03') { // 验证网址
    requiredPara.type = 'url'
  }
  ruleParams.push(requiredPara)
  pageColumn.rules = ruleParams
  pageColumn.span = Number(col.spaceRow)

  return pageColumn
}
/**
 * @Date 2021/1/5 15:20
 * @Author XQC
 * @Description 组装页面数据
 */
export function jsonPage(parData) {
  let isAdd = false
  let isEdit = false
  let isDelete = false
  let isExport = false

  if (parData.isAdd.indexOf('1') > -1) {
    parData.isAdd = '1'
    isAdd = true
  } else {
    parData.isAdd = '0'
  }
  if (parData.isEdit.indexOf('1') > -1) {
    parData.isEdit = '1'
    isEdit = true
  } else {
    parData.isEdit = '0'
  }
  if (parData.isDelete.indexOf('1') > -1) {
    parData.isDelete = '1'
    isDelete = true
  } else {
    parData.isDelete = '0'
  }
  parData.isExport = 0
  parData.isImport = 0


  // if (parData.isExport.indexOf('1') > -1) {
  //   parData.isExport = '1'
  //   isExport = true
  // } else {
  //   parData.isExport = '0'
  // }
  // if (parData.isImport.indexOf('1') > -1) {
  //   parData.isImport = '1'
  //   isImport = true
  // } else {
  //   parData.isImport = '0'
  // }
  const tableOption = {
    border: false,
    index: false,
    indexLabel: '序号',
    title: parData.pageTitle,
    stripe: true,
    menuAlign: 'center',
    searchMenuSpan: 6,
    viewBtn: true,
    excelBtn: isExport,
    editBtn: isEdit,
    delBtn: isDelete,
    align: 'center',
    addBtn: isAdd
  }
  // debugger
  const column = []
  parData.columnVOList.forEach(col => {
    column.push(pageColumnData(col))
  })
  tableOption.column = column
  parData.tableOption = tableOption
  return parData
}

/**
 * @Date 2021/1/5 15:37
 * @Author XQC
 * @Description 表单提交初始化
 */
export function submitData(params) {
  let num = 0
  params.columnVOList.forEach(e => {
    e.columnSort = num
    e.isDict = '0'
    e.isStrong = '0'
    e.isOrder = '0'
    if (e.dictCode != null && e.dictCode !== '' && e.dictCode !== 'null') {
      e.isDict = '1'
    }
    if (e.strongCode != null && e.strongCode !== '' && e.strongCode !== 'null') {
      e.isStrong = '1'
    }
    if (e.orderType != null && e.orderType !== '' && e.orderType !== 'null') {
      e.isOrder = '1'
    }
    num = num + 1
  })
  return params
}

/**
 * @Date 2021/1/5 15:38
 * @Author XQC
 * @Description 初始化选择
 */
export function initSelect(col) {
  col.selectType = '00'
  col.columnInputType = '00'
  col.spaceRow = '12'
  col.isList = '1'
  col.isAdd = '1'
  col.isEdit = '1'
  if (col.isPrincipal === '1') {
    col.strongCode = 'T0001'
    col.isList = '0'
    col.isEdit = '0'
  } else if (col.columnType === 'DATE') {
    // col.strongCode = 'T0002'
    col.columnInputType = '04'
  } else if (col.columnType === 'DATETIME') {
    col.strongCode = 'T0003'
  } else if (col.columnType === 'INT' || col.columnType === 'DECIMAL' || col.columnType === 'DOUBLE' || col.columnType === 'FLOAT') {
    col.columnInputType = '03'
  }
  return col
}
